| Conditions | 11 |
| Total Lines | 63 |
| Code Lines | 49 |
| Lines | 5 |
| Ratio | 7.94 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like EditFacturaCliente.js ➔ businessDocViewSave often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | |||
| 121 | async function businessDocViewSave() |
||
| 122 | { |
||
| 123 | $("#btn-document-save").prop("disabled", true); |
||
| 124 | var infoCliente = await cargarInfoCliente(); |
||
| 125 | logConsole(infoCliente, 'infoCliente'); |
||
| 126 | var datosCliente = JSON.parse(infoCliente); |
||
| 127 | var tipoPago = await cargarTipoPago(); |
||
| 128 | var datosPago = JSON.parse(tipoPago); |
||
| 129 | var tipoNCFs = await cargarTipoNCF('Ventas'); |
||
| 130 | //logConsole(tipoNCFs, 'tipoNCFs'); |
||
| 131 | var datosTipoNCFs = JSON.parse(tipoNCFs); |
||
| 132 | let selectTiposNCF = ""; |
||
| 133 | var descInfoClienteTipoComprobante = ''; |
||
| 134 | $.each(datosTipoNCFs.tipocomprobantes, function (i, value) { |
||
| 135 | let defaultSelected = (datosCliente.infocliente.tipocomprobante === value.tipocomprobante) ? 'selected' : ''; |
||
| 136 | descInfoClienteTipoComprobante = (datosCliente.infocliente.tipocomprobante === value.tipocomprobante) |
||
| 137 | ? value.descripcion : descInfoClienteTipoComprobante; |
||
| 138 | selectTiposNCF += '<option value="'+value.tipocomprobante+'"'+defaultSelected+'>'+value.descripcion+'</option>'; |
||
| 139 | }); |
||
| 140 | |||
| 141 | var ncfTipoPagoCliente = datosCliente.infocliente.ncftipopago; |
||
| 142 | var readOnlySelects = ($("#formSalesDocumentLine #doc_idestado").val() === '11'); |
||
| 143 | var descInfoClienteTipoPago = ''; |
||
| 144 | let selectOptionsPagos = ""; |
||
| 145 | logConsole(ncfTipoPagoCliente, 'ncfTipoPagoCliente'); |
||
| 146 | $.each(datosPago.pagos, function (i, value) { |
||
| 147 | let defaultSelected = ((value.codigo === '17' && ncfTipoPagoCliente === '') || ncfTipoPagoCliente === value.codigo) ? 'selected' : ''; |
||
| 148 | descInfoClienteTipoPago = (datosCliente.infocliente.ncftipopago === value.codigo) |
||
| 149 | ? value.descripcion : descInfoClienteTipoPago; |
||
| 150 | let noSelected = ($("#formSalesDocumentLine #doc_idestado").val() === '11' && defaultSelected !== 'selected') ? ' disabled' : ''; |
||
| 151 | selectOptionsPagos += '<option value="'+value.codigo+'"'+defaultSelected+noSelected+'>'+value.descripcion+'</option>'; |
||
| 152 | }); |
||
| 153 | |||
| 154 | var tipoMovimiento = await cargarTipoMovimiento(); |
||
| 155 | var datosMovimiento = JSON.parse(tipoMovimiento); |
||
| 156 | |||
| 157 | let selectOptionsMovimientos = ""; |
||
| 158 | View Code Duplication | $.each(datosMovimiento.movimientos, function (i, value) { |
|
| 159 | let defaultSelected = (value.codigo === '1') ? 'selected' : ''; |
||
| 160 | let noSelected = ($("#formSalesDocumentLine #doc_idestado").val() === '11' && defaultSelected !== 'selected') ? ' disabled' : ''; |
||
| 161 | selectOptionsMovimientos += '<option value="'+value.codigo+'"'+defaultSelected+noSelected+'>'+value.descripcion+'</option>'; |
||
| 162 | }); |
||
| 163 | |||
| 164 | let message = setBusinessDocViewModalSave( |
||
| 165 | 'Cliente', |
||
| 166 | readOnlySelects, |
||
| 167 | descInfoClienteTipoComprobante, |
||
| 168 | descInfoClienteTipoPago, |
||
| 169 | selectTiposNCF, |
||
| 170 | selectOptionsPagos, |
||
| 171 | selectOptionsMovimientos |
||
| 172 | ); |
||
| 173 | |||
| 174 | executeModal( |
||
| 175 | 'completeNCFData', |
||
| 176 | 'Complete la información faltante', |
||
| 177 | message, |
||
| 178 | 'default', |
||
| 179 | 'saveBussinessDocument' |
||
| 180 | ); |
||
| 181 | |||
| 182 | $("#btn-document-save").prop("disabled", false); |
||
| 183 | } |
||
| 184 |